package com.gorillalogic.scrummonkey.test {
	import mx.rpc.AsyncToken;
	import mx.rpc.Responder;
	import mx.rpc.events.FaultEvent;
	
	import org.flexunit.Assert;
	import org.flexunit.async.Async;
	import org.flexunit.async.TestResponder;

	public class BaseTest {
		public function BaseTest() { }

		protected function callAndThenOrFault(token:AsyncToken, result:Function, fault:Function=null, timeout:int=9999, passThroughData:Object=null):AsyncToken {
			if (token == null) {
				Assert.fail('Token is NULL');
				return null;
			}

			var responder:TestResponder = new TestResponder(result, (fault != null ? fault : defaultFault));

			token.addResponder(Async.asyncResponder(this, responder, timeout, passThroughData));
			return token;
		}

		protected function defaultFault(info:Object, passThroughData:Object):void {
			Assert.fail('Responder threw a fault when result was expected');
		}
	}
}